//修改密码
exports.Login = function (req, res) {

    var bodyParams = req.routeInfo.bodyParams;
    //最终结果
    var resultData = {};



    var u_nickname = bodyParams.u_nickname == "" ? "您还没有昵称" : bodyParams.u_nickname ;

    var openid =  bodyParams.openid;

    var u_username =  bodyParams.u_username;

    var u_password =  bodyParams.u_password;

    var u_header_url =  bodyParams.u_header_url=="" ? "http://testfileupload.oss-cn-beijing.aliyuncs.com/1528378962000-zZQ8TW.png" : bodyParams.u_header_url;

    var u_sex =  bodyParams.u_sex;

    //任务流创建
    async.waterfall([
            //查询该用户是否已经存在
            function (cb) {

                R.SEND_HTTP(
                    req,
                    {
                        url: CORE_APIConfig.coreAPI.userSearch + "/openid/" + openid,
                        method: 'POST',
                        data: {
                            fields: [
                                "u_id",
                            ].join(",")
                        }
                    },
                    function (err, data) {
                        //判断是否有错误信息
                        if (err) {
                            return cb(err, data);
                        }
                        resultData.userData = data.data;
                        cb();
                    }
                );

            },
            function (cb) {
                if (resultData.userData.length == 0) {
                    R.SEND_HTTP(
                        req,
                        {
                            url: CORE_APIConfig.coreAPI.userAdd,
                            method: 'POST',
                            data: {
                                openid: openid,
                                u_nickname: u_nickname,
                                u_header_url: u_header_url,
                                u_username: u_username,
                                u_password: u_password,
                                u_sex: u_sex
                            }
                        },
                        function (err, data) {

                            //判断是否有错误信息
                            if (err) {
                                return RES.response(res, false, data);
                            }
                            resultData.res = data;
                            cb();
                        }
                    );
                }else{
                    resultData.res =resultData.userData[0].u_id ;
                    cb();
                }
            },

        ], function (err, result) {
            //返回最终拼接结果
            RES.response(res, true, resultData);

        }
    );

}